#from turbogears import expose, redirect
#from mnemoply._renewed_lib.crud import CRUDController, TableCol
#from mnemoply._renewed_model.field import EducationAgreement as model_GroupReserve,\
#                                          StudentNew, Personality
#from mnemoply._renewed_lib.validators import tg_validators, EqualAccountFromTwoPersonalities, NoSamePlan
#from mnemoply.model.field import Group
#
#class GroupReserveSchema(tg_validators.Schema):
#    customerID = tg_validators.Int(not_empty=True)
#    studentID = tg_validators.Int(not_empty=True)
#    groupID=tg_validators.Int(not_empty=True)
#    chained_validators = [EqualAccountFromTwoPersonalities('customerID', 'studentID'),NoSamePlan('groupID','studentID')]
#
#class GroupReserveController(CRUDController):
#    model_object = model_GroupReserve
#    mysql_view_name = 'prod_v2.group_reserve_lookup'
#    lookup_columns = [
#        TableCol(name='ed_group', caption=_('Group')),
#        TableCol(name='student', caption=_('Student')),
#        TableCol(name='customer', caption=_('Customer')),
#        TableCol(name='date_enter', caption=_('Date enter')),
#        TableCol(name='account', caption=_('Account')),
#   ]
#
#    view_fields = [
#        'studentID',
#        'customerID',
#        'groupID',
#        'discontID',
#        'cameFromID',
#       # 'prefered_day',
#        'dateEnter' ,
#        'dateCreation',
#        'amount_reserve',
#        'comment'
#        ]
#    edit_fields = add_fields = view_fields
#    chained_validators_edit=[EqualAccountFromTwoPersonalities('customerID', 'studentID'),NoSamePlan('groupID','studentID')]
#    #schema = GroupReserveSchema
#    
#    #def get_validator_edit(self):
#    #    return self.schema()
#    #def get_validator_add(self):
#    #    return self.schema()
#
#    def before_update(self, data, obj=None):
#        customer = Personality.get(int(data['customerID']))
#        data['accountID']=customer.account.id
#        student = StudentNew.get(int (data['studentID']))
#        if not list(model_GroupReserve.selectBy(student=student)):
#            group=Group.get(int(data['groupID']))
#            student.academic_year_admission = group.initialPlan.year
#        return CRUDController.before_update(self, data)
#
#    def redirect_after(self, came_from=None, obj=None):
#        if not obj:
#            return '/GroupReserve_new'
#        student = StudentNew.get(obj.student.id)
#
#        is_correct = student.isStudent \
#                    and student.student_typeID \
#                    and student.birthday\
#                    and student.academic_year_admission
#
#        if student.student_typeID ==2:
#            is_correct = is_correct \
#                         and student.school_name \
#                         and student.school_form 
#        
#            
#        if not is_correct:
#            return "/Student_new/%s/edit_req"%student.id
#        return '/GroupReserve_new'
#    
#    